package me.midday.java.base.knowledge.mutlthread;

/**
 * 某个线程调用另一个线程的Join方法，调用线程将背阻塞，知道被调用线程执行完。join还可以设置等待时间
 */

public class JoinThread extends Thread{
    public JoinThread(String name){
        super(name);
    }

    @Override
    public void run(){
        for (int i = 0; i< 100; i++){
            // 线程中发生没捕获的异常
            if (i == 30){
                int a = 1 / 0;
            }
            System.out.println(getName() +  " " + i);
        }
    }
    public static void main(String[] args) throws InterruptedException {
        new JoinThread("新线程").start();
        for(int i = 0; i < 100; i++){
            if (i == 20){
                JoinThread jt = new JoinThread("被Join的线程");
                jt.start();
                jt.join();
            }
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }

}
